unit TanksGantt;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeEngine, Series, GanttCh, ExtCtrls, TeeProcs, Chart, StdCtrls,
  RzLabel, WOT_Base;

type
  TTankGanttForm = class(TForm)
    Chart1: TChart;
    Series14: TGanttSeries;
    Series1: TGanttSeries;
    Shape1: TShape;
    RzLabel7: TRzLabel;
    Shape2: TShape;
    RzLabel1: TRzLabel;
    Shape3: TShape;
    RzLabel2: TRzLabel;
    Shape4: TShape;
    RzLabel3: TRzLabel;
    RzLabel4: TRzLabel;
    L_Sum: TRzLabel;

    procedure DrawGantt(const O:TObject);
    procedure Chart1Resize(Sender: TObject);

  end;

var
  TankGanttForm: TTankGanttForm;

implementation

{$R *.dfm}

uses Main;

{ TTankGanttForm }

 procedure TTankGanttForm.Chart1Resize(Sender: TObject);
  begin
   L_Sum.Left :=  Chart1.Width - (992-707);
  end;

 procedure TTankGanttForm.DrawGantt(const O:TObject);
  var PL      : TPlayer;
      i,j,k   : Integer;
      Ts      : TTankStatArray;
      ModName,s : String;
      YPos    : Real;
      A,B : TTankStat;
      Astat,BStat : TTankStatArray;
      Aday,Bday : TDateTime;
      Res,Sum : Integer;
      Col : TColor;
  begin
   PL := O as TPlayer;
   if PL=Nil then Exit;
   Chart1[0].Clear;
   Chart1[1].Clear;
   Ts := PL.ActualStat.TankStats;
   YPos := Length(Ts);
   Sum  := 0;
   for i:=0 to High(Ts) do
    begin
     ModName := Ts[i].Tank;
     for j:=1 to PL.HistSize-1 do
      begin
       // A
       A := TankStatByName(ModName,PL.Hist[j-1].TankStats);
       if A.Tank='' then Continue;
       Aday := SelectDate(PL.Hist[j-1].StatDate);
       // B
       B := TankStatByName(ModName,PL.Hist[j].TankStats);
       Bday := SelectDate(PL.Hist[j].StatDate);
       // Draw
       Res := TankProgress2(A,B);
       if B.Battle-A.Battle=0 then Col := clGray else
       if Res>0 then Col := clGreen else
       if Res<0 then Col := clRed else Col := clYellow;
       (Chart1[0] as TGanttSeries).AddGanttColor(Aday,Bday,YPos,''{ModName},Col);
      end;
     //
     A    := TankStatByName(ModName,PL.ActualStat.TankStats);
     Aday := MsToTime(TimeToMs(SelectDate(PL.ActualStat.StatDate))+24*60*60*1000/4);
     Bday := MsToTime(TimeToMs(Aday)+24*60*60*1000/4);
     Res := TankProgress1(A);
     Sum := Sum + Res;
     if Res>0 then Col := clGreen else
     if Res<0 then Col := clRed else Col := clYellow;
     s := ExpandStr(Format('%s%d',[SGN(Res),Abs(Res)]),5,1);
     (Chart1[1] as TGanttSeries).AddGanttColor(Aday,Bday,YPos,Format('%s : %s',[s,ModName]),Col);
     //
     YPos := YPos - 1;
    end;
   L_Sum.Caption := Format('In Total : %s%d',[SGN(Sum),Abs(Sum)]);
  end;

end.
